<html>
<head><meta charset="utf-8"><title>Padding · t-lang/doc · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/237824-t-lang/doc/index.html">t-lang/doc</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/237824-t-lang/doc/topic/Padding.html">Padding</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="209163355"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/237824-t-lang/doc/topic/Padding/near/209163355" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> isHavvy <a href="https://rust-lang.github.io/zulip_archive/stream/237824-t-lang/doc/topic/Padding.html#209163355">(Sep 05 2020 at 05:46)</a>:</h4>
<p>Should we describe <em>padding</em> as a type?</p>



<a name="209163462"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/237824-t-lang/doc/topic/Padding/near/209163462" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> isHavvy <a href="https://rust-lang.github.io/zulip_archive/stream/237824-t-lang/doc/topic/Padding.html#209163462">(Sep 05 2020 at 05:51)</a>:</h4>
<p>From the perspective of the reference. Padding is like a field added automatically to various other types. It's never nameable of course, but it's still there.</p>



<a name="209167953"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/237824-t-lang/doc/topic/Padding/near/209167953" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/237824-t-lang/doc/topic/Padding.html#209167953">(Sep 05 2020 at 08:30)</a>:</h4>
<p>we could do this -- though I feel it is easier to describe as the gap between where the fields/types are</p>



<a name="209167955"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/237824-t-lang/doc/topic/Padding/near/209167955" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/237824-t-lang/doc/topic/Padding.html#209167955">(Sep 05 2020 at 08:30)</a>:</h4>
<p>that also more intuitively explains why its content is lost on copy</p>



<a name="209170566"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/237824-t-lang/doc/topic/Padding/near/209170566" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> isHavvy <a href="https://rust-lang.github.io/zulip_archive/stream/237824-t-lang/doc/topic/Padding.html#209170566">(Sep 05 2020 at 09:49)</a>:</h4>
<p>Hmm, I should try to write a rough draft then. Though not tonight. I'm already past my bedtime.</p>



<a name="209950816"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/237824-t-lang/doc/topic/Padding/near/209950816" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Connor Horman <a href="https://rust-lang.github.io/zulip_archive/stream/237824-t-lang/doc/topic/Padding.html#209950816">(Sep 13 2020 at 21:42)</a>:</h4>
<p>When I wrote something similar for a different language, I simply noted that there are two different representations: the <em>object-representation</em> which is the contiguous sequence of bytes that make up an object (which is nothing more than a region of storage allocated for the purposes of representing some value of some type for some lifetime), and the <em>value-representation</em> which are the bytes that determine the value. It doesn't explicitly mention padding, but it notes that object types may have  bytes in the <em>object-representation</em> which do not participate in the <em>value-representation</em>,  and that such bytes may be uninitialized. Rust could likely adopt similar wording, not mentioning padding by a name, but simply saying that some types may have bytes in the <em>object-representation</em> (or the equivalent for rust) that are not used to determine that value, and that they may be uninitialized.</p>



<a name="209972600"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/237824-t-lang/doc/topic/Padding/near/209972600" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/237824-t-lang/doc/topic/Padding.html#209972600">(Sep 14 2020 at 07:31)</a>:</h4>
<p><span class="user-mention" data-user-id="257758">@Connor Horman</span> you mean, something like <a href="https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/value-domain.md">https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/value-domain.md</a> ?</p>



<a name="209972621"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/237824-t-lang/doc/topic/Padding/near/209972621" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/237824-t-lang/doc/topic/Padding.html#209972621">(Sep 14 2020 at 07:31)</a>:</h4>
<p>but given that padding is a thing people coming to Rust already know, and what to know how it works here, I think we have to use the term</p>



<a name="209972725"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/237824-t-lang/doc/topic/Padding/near/209972725" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/237824-t-lang/doc/topic/Padding.html#209972725">(Sep 14 2020 at 07:32)</a>:</h4>
<p>(also, for <code>union</code> types defining the "value representation" will likely have to explicitly <a href="https://github.com/rust-lang/unsafe-code-guidelines/issues/156">talk about padding</a> :/ )</p>



<a name="209992160"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/237824-t-lang/doc/topic/Padding/near/209992160" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Connor Horman <a href="https://rust-lang.github.io/zulip_archive/stream/237824-t-lang/doc/topic/Padding.html#209992160">(Sep 14 2020 at 11:31)</a>:</h4>
<p><span class="user-mention silent" data-user-id="120791">RalfJ</span> <a href="#narrow/stream/237824-t-lang.2Fdoc/topic/Padding/near/209972600">said</a>:</p>
<blockquote>
<p><span class="user-mention silent" data-user-id="257758">Connor Horman</span> you mean, something like <a href="https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/value-domain.md">https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/value-domain.md</a> ?</p>
</blockquote>
<p>Seems similar in concept. <code>[r]</code> seems to be the <em>object-representation</em>.  </p>
<p><span class="user-mention silent" data-user-id="120791">RalfJ</span> <a href="#narrow/stream/237824-t-lang.2Fdoc/topic/Padding/near/209972621">said</a>:</p>
<blockquote>
<p>but given that padding is a thing people coming to Rust already know, and what to know how it works here, I think we have to use the term</p>
</blockquote>
<p>My point may still be useful, simply with a note (possibly a non-normative note) that such bytes are called "Padding Bytes" (I believe that in the specification I mentioned, I did include a non-normative note naming those bytes "padding bytes", but only because any further mention was only made in other notes).</p>
<p>For unions, I used something similar to C++'s active member, which rust could similarily adopt. Rather than being UB to access in inactive member, you can directly access any variant provided it yields a valid value. </p>
<p>(I also add special cases for zeroed memory, as well as common-initial sequence requirements)</p>



<a name="210020871"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/237824-t-lang/doc/topic/Padding/near/210020871" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/237824-t-lang/doc/topic/Padding.html#210020871">(Sep 14 2020 at 15:21)</a>:</h4>
<p>ooh let's not use "active member". <a href="https://doc.rust-lang.org/reference/items/unions.html#reading-and-writing-union-fields">the reference</a> currently doesn't do it, and it'd be a bad move to add active members into the mix.</p>



<a name="210032891"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/237824-t-lang/doc/topic/Padding/near/210032891" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/237824-t-lang/doc/topic/Padding.html#210032891">(Sep 14 2020 at 16:54)</a>:</h4>
<p>yeah, active members are not a thing in Rust if I have any say in how unions work^^</p>



<a name="210032932"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/237824-t-lang/doc/topic/Padding/near/210032932" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/237824-t-lang/doc/topic/Padding.html#210032932">(Sep 14 2020 at 16:55)</a>:</h4>
<p><span class="user-mention" data-user-id="257758">@Connor Horman</span> sure, I didn't mean to imply that padding was normative -- for most types, it is a "derived notion".</p>



<a name="210033085"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/237824-t-lang/doc/topic/Padding/near/210033085" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/237824-t-lang/doc/topic/Padding.html#210033085">(Sep 14 2020 at 16:56)</a>:</h4>
<p>however, for unions, I think we have to actually include this definition in the normative part... I wish the value representation of unions is just "a sequence of bytes of the appropriate length" (i.e., identical to the object representation), but to reflect what real calling conventions to we'll likely have to say that the value representation has "gaps" when there is padding in the field types :/</p>



<a name="210094401"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/237824-t-lang/doc/topic/Padding/near/210094401" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> isHavvy <a href="https://rust-lang.github.io/zulip_archive/stream/237824-t-lang/doc/topic/Padding.html#210094401">(Sep 15 2020 at 06:31)</a>:</h4>
<p>I'm way too distracted by Final Fantasy 14, and knowing me, I'll be distracted for a few more months. Connor, since you've done this kind of thing before, do you want to take your hand at writing about padding?</p>
<p>I also think it's important to name these things so that people can <em>search</em> for them. Obscuring concepts is a bad idea.</p>



<a name="210207457"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/237824-t-lang/doc/topic/Padding/near/210207457" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Connor Horman <a href="https://rust-lang.github.io/zulip_archive/stream/237824-t-lang/doc/topic/Padding.html#210207457">(Sep 16 2020 at 00:02)</a>:</h4>
<p><span class="user-mention silent" data-user-id="296643">isHavvy</span> <a href="#narrow/stream/237824-t-lang.2Fdoc/topic/Padding/near/210094401">said</a>:</p>
<blockquote>
<p>I'm way too distracted by Final Fantasy 14, and knowing me, I'll be distracted for a few more months. Connor, since you've done this kind of thing before, do you want to take your hand at writing about padding?</p>
<p>I also think it's important to name these things so that people can <em>search</em> for them. Obscuring concepts is a bad idea.</p>
</blockquote>
<p>I can certainly try. Is there a particular place I should write the draft, or is just here in the zulip topic fine?</p>
<p>I do agree naming things are important, but I don't believe that padding is important enough to warrant a normative term, and simply mentioning that it can be called padding in a note is sufficient.</p>



<a name="210211327"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/237824-t-lang/doc/topic/Padding/near/210211327" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> isHavvy <a href="https://rust-lang.github.io/zulip_archive/stream/237824-t-lang/doc/topic/Padding.html#210211327">(Sep 16 2020 at 01:00)</a>:</h4>
<p>A PR against the reference would be best, but failing that, posting it in here works too.</p>



<a name="210250985"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/237824-t-lang/doc/topic/Padding/near/210250985" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/237824-t-lang/doc/topic/Padding.html#210250985">(Sep 16 2020 at 12:01)</a>:</h4>
<p>not sure what exactly you mean by "normative term", but IMO it should appear in the glossary</p>



<a name="210251021"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/237824-t-lang/doc/topic/Padding/near/210251021" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/237824-t-lang/doc/topic/Padding.html#210251021">(Sep 16 2020 at 12:01)</a>:</h4>
<p>to teach people this stuff we have to start with what they know, and many have at least heard the term "padding" in a C context</p>



<a name="210251060"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/237824-t-lang/doc/topic/Padding/near/210251060" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/237824-t-lang/doc/topic/Padding.html#210251060">(Sep 16 2020 at 12:01)</a>:</h4>
<p>the Rust reference isn't nearly as structured and normative as the C/C++ standard, and IMO that's fine at the current stage</p>



<a name="210330094"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/237824-t-lang/doc/topic/Padding/near/210330094" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Connor Horman <a href="https://rust-lang.github.io/zulip_archive/stream/237824-t-lang/doc/topic/Padding.html#210330094">(Sep 16 2020 at 22:57)</a>:</h4>
<p>That's entirely fair. Though I am very interested in rust having a full specification, rather than rust being monolithic system which is simply defined by the sole correct implementation.<br>
A "Normative Term" is simply a term that has meaning assigned by the specification (rather than simply in a note), and therefore can be referenced by it.</p>



<a name="210334947"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/237824-t-lang/doc/topic/Padding/near/210334947" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/237824-t-lang/doc/topic/Padding.html#210334947">(Sep 17 2020 at 00:06)</a>:</h4>
<p>I think we largely do want to get there some day, but just disagree about the expected time scale to get there.</p>



<a name="210504257"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/237824-t-lang/doc/topic/Padding/near/210504257" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/237824-t-lang/doc/topic/Padding.html#210504257">(Sep 18 2020 at 11:07)</a>:</h4>
<p>yeah I certainly want a full spec for Rust. in my eyes, a "full spec" is at least partially a  mathematical document though, not a bunch of plain English. something more <a href="https://dl.acm.org/doi/10.1145/3140587.3062363">like this</a>.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>